﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using WorldSource.Entities;

namespace WorldSource.GUI
{
    public class GUIObject
    {
        private Boolean mouseEntered = false;
        public SpriteFont spriteFont;
        public Rectangle area;
        public InputHandler inputHandler;

        public delegate void ClickedHandler(object sender);
        public event ClickedHandler onClicked;

        public delegate void MouseEnterHandler(object sender);
        public event MouseEnterHandler onMouseEnter;

        public delegate void MouseLeaveHandler(object sender);
        public event MouseLeaveHandler onMouseLeave;


        public GUIObject()
        {
            inputHandler = Game1.inputHandler;
            spriteFont = Game1.game.Content.Load<SpriteFont>("SpriteFont1");
        }

        public virtual void Update()
        {
            if (inputHandler.mouseState.LeftButton == ButtonState.Released && inputHandler.prevMouseState.LeftButton == ButtonState.Pressed && inputHandler.mouseState.X > area.Left && inputHandler.mouseState.X < area.Right && inputHandler.mouseState.Y > area.Top && inputHandler.mouseState.Y < area.Bottom)
            {
                if(onClicked != null)
                    onClicked(this);
            }

            if (inputHandler.mouseState.X > area.Left && inputHandler.mouseState.X < area.Right && inputHandler.mouseState.Y > area.Top && inputHandler.mouseState.Y < area.Bottom)
            {
                if (onMouseEnter != null)
                {
                    onMouseEnter(this);
                    mouseEntered = true;
                }
            }
            else
            {
                if (onMouseLeave != null)
                {
                    if (mouseEntered == true)
                    {
                        onMouseLeave(this);
                        mouseEntered = false;
                    }
                }
            }
        }
        public virtual void Draw()
        {
        }
    }
}
